<?php

namespace app\controller;

class NotificationController extends BaseController
{
    /**
     * 将指定ID的通知标记为已读
     * @param int $id 通知ID
     */
    public function read(int $id): void
    {
        $this->requireLogin();
        $currentUserId = $this->getCurrentUserId();

        if (isset($_SESSION['notifications'][$id])) {
            // 确保用户只能将自己的通知标记为已读
            if ($_SESSION['notifications'][$id]['user_id'] === $currentUserId) {
                $_SESSION['notifications'][$id]['is_read'] = true;
            }
        }

        // 重定向上一个页面
        $this->redirect($_SERVER['HTTP_REFERER'] ?? '/');
    }
}
